package net.oschina.app.fragment.center_message;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;

import com.chanven.lib.cptr.recyclerview.RecyclerAdapterWithHF;

import net.oschina.app.adapter.center_message.NewsMessageAdapter;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.bean.MessagesBean;
import net.oschina.app.interf.FragmentType;
import net.oschina.app.protocol.me_messager.NewsMessageProtocol;
import net.oschina.app.ui.DetailFragmentActivity;
import net.oschina.app.util.CommonUtils;

import java.util.List;

/**
 * Created by wei03 on 2017/1/14.
 */
public class NewMessageFragment extends BaseFragment {
    private NewsMessageAdapter mNewsMessageAdapter;
    private List<MessagesBean.MessageBean> mMessageBeen;

    @Override

    protected BaseAdapter getRvAdapter() {
        mNewsMessageAdapter = new NewsMessageAdapter();
        return mNewsMessageAdapter;
    }

    @Override
    protected void OnSubItemClick(RecyclerAdapterWithHF adapter, RecyclerView.ViewHolder vh, int position) {
        Intent intent = new Intent(CommonUtils.getContext(), DetailFragmentActivity.class);
        intent.putExtra(FragmentType.FRAGMENT_TYPE, FragmentType.TYPE_ME_NEWMESSAGE_DETAIL);
        String friendname = mMessageBeen.get(position).getFriendname();
        intent.putExtra("title", friendname);
        startActivity(intent);
    }

    @Override
    protected int onLoadSubData() {
        NewsMessageProtocol newsMessageProtocol = new NewsMessageProtocol();
        final MessagesBean messagesBean = newsMessageProtocol.getData(mList.size() / 2);
        if (messagesBean != null) {
            CommonUtils.runOnMainThread(new Runnable() {
                @Override
                public void run() {
                    mMessageBeen = messagesBean.getMessages();
                    mNewsMessageAdapter.setDatas(mMessageBeen);
                }
            });
            return STATE_SUCCESS;
        }

        return STATE_EMPTY;
    }
}
